翻訳と辞書
Words near each other
・ Thread (network protocol)
・ Thread (yarn)
・ Thread angle
・ Thread automaton
・ Thread control block
・ Thread eel
・ Thread of Lies
・ Thread of Time
・ Thread pitch gauge
・ Thread pool pattern
・ Thread protector
・ Thread restorer
・ Thread Routes
・ Thread safety
・ Thread seal tape
Thread-local storage
・ Thread-locking fluid
・ Threadbombing
・ Threaded binary tree
・ Threaded code
・ Threaded fastener
・ Threaded insert
・ Threaded marketing
・ Threaded pipe
・ Threaded rod
・ Threadfin
・ Threadfin bream
・ Threadfin butterflyfish
・ Threadfin cardinalfish
・ Threadfin cichlid


Dictionary Lists
翻訳と辞書 辞書検索 [ 開発暫定版 ]
スポンサード リンク

Thread-local storage : ウィキペディア英語版
Thread-local storage

Thread-local storage (TLS) is a computer programming method that uses static or global memory local to a thread.
TLS is used in some places where ordinary, single-threaded programs would use global variables but where this would be inappropriate in multithreaded cases. An example of such situations is where functions use a global variable to set an error condition (for example the global variable errno used by many functions of the C library). If errno were a global variable, a call of a system function on one thread may overwrite the value previously set by a call of a system function on a different thread, possibly before following code on that different thread could check for the error condition. The solution is to have errno be a variable that looks like it is global, but in fact exists once per thread -- i.e., it lives in thread-local storage. A second use case would be multiple threads accumulating information into a global variable. To avoid a race condition, every access to this global variable would have to be protected by a mutex. Alternatively, each thread might accumulate into a thread-local variable (that, by definition, can not be read from or written to from other threads, implying that there can be no race conditions). Threads then only have to synchronise a final accumulation from their own thread-local variable into a single, truly global variable.
Many systems impose restrictions on the size of the thread-local memory block, in fact often rather tight limits. On the other hand, if a system can provide at least a memory address (pointer) sized variable thread-local, then this allows the use of arbitrarily sized memory blocks in a thread-local manner, by allocating such a memory block dynamically and storing the memory address of that block in the thread-local variable.
==Windows implementation==
The application programming interface (API) function TlsAlloc can be used to obtain an unused ''TLS slot index''; the ''TLS slot index'' will then be considered ‘used’.
The TlsGetValue and TlsSetValue functions are then used to read and write a memory address to a thread-local variable identified by the ''TLS slot index''. TlsSetValue only affects the variable for the current thread. The TlsFree function can be called to release the ''TLS slot index''.
There is a Win32 Thread Information Block for each thread. One of the entries in this block is the thread-local storage table for that thread.
TlsAlloc returns an index to this table, unique per address space, for each call. Each thread has its own copy of the thread-local storage table. Hence, each thread can independently use TlsSetValue(index) and obtain the specified value via TlsGetValue(index), because these set and look up an entry in the thread's own table.
Apart from TlsXxx function family, Windows executables can define a section which is mapped to a different page for each thread of the executing process. Unlike TlsXxx values, these pages can contain arbitrary and valid addresses. These addresses, however, are different for each executing thread and therefore should not be passed to asynchronous functions (which may execute in a different thread) or otherwise passed to code which assume that a virtual address is unique within the whole process. TLS sections are managed using memory paging and its size is quantized to a page size (4kB on x86 machines).
Such sections may only be defined inside a main executable of a program - DLLs should not contain such sections, because they are not correctly initialized when loading with LoadLibrary.

抄文引用元・出典: フリー百科事典『 ウィキペディア(Wikipedia)
ウィキペディアで「Thread-local storage」の詳細全文を読む



スポンサード リンク
翻訳と辞書 : 翻訳のためのインターネットリソース

Copyright(C) kotoba.ne.jp 1997-2016. All Rights Reserved.